import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login.vue"
import Home from "../components/Home.vue"
import Users from "../components/user/users.vue"
import Welcome from "../components/welcome.vue"
import Rights from "../components/rights/rights.vue"
import Roles from "../components/rights/roles.vue"
import Catetory from "../components/good_cate/catetory.vue"
import Params from "../components/good_cate/params.vue"
import GoodsList from "../components/good_cate/goods_list.vue"
import Orders from '../components/orders/orders.vue'
import Reports from '../components/repots/reports.vue'
Vue.use(VueRouter)



const router = new VueRouter({
    routes: [
        { path: '/', redirect: '/login' },
        { path: '/login', component: Login },
        {
            path: '/home',
            component: Home,
            children: [
                { path: '/', component: Welcome },
                { path: '/welcome', component: Welcome },
                { path: '/users', component: Users },
                { path: '/rights', component: Rights },
                { path: '/roles', component: Roles },
                { path: '/categories', component: Catetory },
                { path: '/params', component: Params },
                { path: '/goods', component: GoodsList },
                {path:'/orders',component:Orders},
                {path:'/reports',component:Reports}
                
            ]
        }
    ]
})
router.beforeEach((to, from, next) => {
    if (to.path == '/login') return next();
    const totken = window.sessionStorage.getItem('token');
    if (!totken) return next('/login');
    next();
})

export default router